import { articleList } from "../../../api/index";

// pages/tabBar/article/index.ts
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        dictData:[
            {
                id:''
            }
        ],
        id:"",
        articleData:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        const app = getApp();
        // 获取实例上存储的数据
        this.setData({
            dictData: app.globalData.articleDict,
            id: app.globalData.articleDict[this.data.active].id
        });
    },

    getData(id:string){
        articleList(id).then((r:any)=>{
            this.setData({
                articleData:r
            })   
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getData(this.data.id)
    },
    // tab切換
    tabChange(e:{detail:{index:number}}) {
        const i = e.detail.index;
        this.setData({
            active:i,
            id:this.data.dictData[i].id
        });
        
        this.getData(this.data.dictData[i].id);
    }
})